/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.img;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * <p>Project: app2022 - Img8
 * <p>Powered by webrx On 2022-01-21 17:49:06
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Img8 {
    public static void main(String[] args) {
        var w = 800;
        var h = 800;
        var t = 2;
        var i = new BufferedImage(w, h, t);
        var g = i.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setColor(Color.ORANGE);
        g.fillRect(0, 0, w, h);

        g.setColor(Color.WHITE);
        int xx = 400, yy = 300;//坐标中心
        int angle = 0;//角度
        int cw = 100, ch = 200;//控制圆形的水平直径 垂直直径
        for (int n = 0; n <= 36; n++) {
            int x = xx - (int) (Math.sin(angle * Math.PI / 360) * cw);
            int y = yy - (int) (Math.cos(angle * Math.PI / 360) * ch);
            g.fillOval(x, y, 10, 10);
            angle += 20;
        }

        cw = 230;
        ch = 230;//控制圆形的水平直径 垂直直径
        for (int n = 0; n <= 360; n++) {
            int x = xx - (int) (Math.sin(angle * Math.PI / 360) * cw);
            int y = yy - (int) (Math.cos(angle * Math.PI / 360) * ch);
            g.fillOval(x, y, 10, 10);
            angle += 5;
        }

        g.dispose();
        //保存图像文件
        try {
            ImageIO.write(i, "png", new File("i.png"));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //打开图像文件
        try {
            Runtime.getRuntime().exec("cmd /k start i.png");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
